/*
 * Copyright (c) 2001 Boris Pruessmann and others.
 * All rights reserved.   This program and the accompanying materials
 * are made available under the terms of the Common Public License v0.5
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-v05.html
 * 
 * Contributors:
 *    Boris Pruessmann - Initial implementation.
 */
package net.sourceforge.p4eclipse.core.resources;

import net.sourceforge.p4eclipse.core.Policy;
import net.sourceforge.p4eclipse.core.syncinfo.ResourceSyncInfo;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;

/**
  * @version 	1.0
  * @author		<a href="mailto:bpruessmann@users.sourceforge.net">Boris Pruessmann</a>
  */
public abstract class LocalResource
{
	private IResource resource;
	
	public static LocalResource createFromResource(IResource resource)
	{
		LocalResource localResource = null;
		if (resource instanceof IFile)
			localResource = new LocalFile((IFile)resource);
		else
		if (resource instanceof IContainer)
			localResource = new LocalFolder((IContainer)resource);		
		
		return localResource;
	}
	
	/**
	  * Constructs a new LocalResource
	  */
	public LocalResource(IResource resource)
	{
		Policy.assertNotNull(resource);
		this.resource = resource;
	}
	
	/**
	  * Checks whether the local resource exists.s
	  */
	public boolean exists()
	{
		return resource.exists();
	}

	public boolean isIgnored()
	{	
		//IPath path = toResource().getProjectRelativePath();
		//
		//return path.matchingFirstSegments(new Path("bin")) == 1;
		return false;
	}
	
	/**
	  * Returns the absolute pathname string of this abstract pathname. 
	  */
	public String getAbsolutePath()
	{
		return resource.getLocation().toOSString();
	}
	
	/**
	  * Returns the resource's sync info.
	  */
	public abstract ResourceSyncInfo getSyncInfo();

	public IResource toResource()
	{
		return resource;
	}
	
	public abstract boolean hasRemote();
	
	public abstract boolean isCheckedOut();

	public abstract boolean isDirty();

	public abstract boolean isOutOfDate();
}
